package cn.itsource.org.controller;

import cn.itsource.basic.util.AjaxResult;
import cn.itsource.basic.util.PageList;
import cn.itsource.org.Dto.rejectShopDto;
import cn.itsource.org.domain.Shop;
import cn.itsource.org.query.ShopQuery;
import cn.itsource.org.service.IShopService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController //@Controller + @ResponseBody的结合体
@RequestMapping("/shop") //暴露公共路径
@Api(tags = "商铺管理接口")  //swagger API
public class ShopController {

    @Autowired
    private IShopService shopService;
    @PostMapping("/settlement")
    @ApiOperation(value = "店铺入驻") //swagger API
    public AjaxResult settlement( @RequestBody Shop shop){
        AjaxResult settlement = shopService.settlement(shop);
        return AjaxResult.createSuccess(settlement);
    }
    @RequestMapping("/active/{uuid}/{id}")
    @ApiOperation(value = "激活店铺") //swagger API
    public AjaxResult settlement( @PathVariable("uuid") String uuid, @PathVariable("id") Long id){
       return shopService.active(uuid,id);
    }

    /**
     * 查询所有
     * @return
     */
    @GetMapping
    @ApiOperation(value = "查询所有的员工") //swagger API
    public AjaxResult list(){

        //查询
        List<Shop> list = shopService.findAll();
        //返回
        return AjaxResult.createSuccess(list);
    }
    /**
     * 查询员工分页
     * @return
     */
    @PostMapping("/findPage")
    @ApiOperation(value = "查询员工分页") //swagger API
    public PageList<Shop> findPage(@RequestBody ShopQuery query){
        //查询
        return shopService.findPageList(query);
    }


    /**
     *
     * @return
     */
    @PostMapping
    @ApiOperation(value = "更改通过状态") //swagger API
    public AjaxResult saveOrUpdate(@RequestBody Shop shop){
        shopService.update(shop);
        return AjaxResult.createSuccess();
    }
    /**
     *
     * @return
     */
    @ApiOperation(value = "根据修改审核驳回状态") //swagger API
    @PostMapping("/reject")
    public AjaxResult reject(@RequestBody rejectShopDto dto){
        try {
            shopService.reject(dto);
            return AjaxResult.createSuccess();
        } catch (Exception e) {
            //打印错误的堆栈信息
            e.printStackTrace();
            return AjaxResult.createError();
        }
    }
    //    批量删除
    @PostMapping("/batchRemove")
    @ApiOperation(value = "根据id删除部门对象")
    public AjaxResult deleteDatch(@RequestBody ShopQuery query){
        shopService.batchRemove(query);
        return AjaxResult.createSuccess();
    }

}
